﻿using Aop.Api;
using Aop.Api.Request;
using Aop.Api.Response;
using Coldairarrow.Util.Pay.AlipayPay;

namespace Coldairarrow.Entity.Pay
{
    public class AliTransfer
    {

        /// <summary>
        /// 退款
        /// </summary>
        /// <returns></returns>
        public static AlipayFundTransUniTransferResponse AlipayRefundMoney(string appId,string privateKey,string publickey, CertParams certParams,string tsfId,decimal amount, string aliName,string userName)
        {

            //设置证书相关参数
            //CertParams certParams = new CertParams
            //{
            //    AlipayPublicCertPath = "支付宝公钥证书路径",
            //    AppCertPath = "商户应用证书路径",
            //    RootCertPath = "支付宝根证书路径"
            //};
            IAopClient client = new DefaultAopClient(Config.Gatewayurl, Config.AppId, Config.PrivateKey, "json", "1.0",
                    Config.SignType, Config.CharSet, false,certParams);
            AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
            request.BizContent = "{" +
            "\"out_biz_no\":\""+ tsfId + "\"," +
            "\"trans_amount\":" + amount.ToString("0.00") + "," +
            "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +
            "\"biz_scene\":\"DIRECT_TRANSFER\"," +
            "\"order_title\":\"主动体现" + amount.ToString("0.0") + "\"," +
            "\"payee_info\":{" +
            "\"identity\":\"" + aliName + "\"," +
            "\"identity_type\":\"ALIPAY_LOGON_ID\"," +
            "\"name\":\"" + userName + "\"" +
            "}" +
            "}";
            AlipayFundTransUniTransferResponse response = client.CertificateExecute(request);

            return response;
        }
    }
}
